package com.bob.light.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.viewpager.widget.ViewPager
import com.bob.light.R
import com.bob.light.adapter.MainPagerAdapter
import kotlinx.android.synthetic.main.app_activity_main.*

class MainActivity : BackPressedWrapperActivity() {

    companion object {

        @JvmStatic
        fun navigation(activity: AppCompatActivity?) {
            activity?.let { context ->
                val intent = Intent(context, MainActivity::class.java)
                context.startActivity(intent)
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.app_activity_main)
        initViewPager()
    }

    private fun initViewPager() {
        vp_main?.adapter = MainPagerAdapter(layoutInflater)
            .setOnStartActivityListener {  position ->
                when(position) {
                    0 -> FamilyManagerActivity.navigation(this@MainActivity)
                    1 -> ActivatorManagerActivity.navigation(this@MainActivity)
                    2 -> DeviceManagerActivity.navigation(this@MainActivity)
                }
            }
        vp_main?.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
            override fun onPageSelected(position: Int) {
                when(position) {
                    0 -> tv_scroll_tip?.text = getString(R.string.app_main_right_scroll_tip)
                    1 -> {
                        val leftTip = getString(R.string.app_main_left_scroll_tip)
                        val rightTip = getString(R.string.app_main_right_scroll_tip)
                        val text = "$leftTip -- $rightTip"
                        tv_scroll_tip?.text = text
                    }
                    2 -> tv_scroll_tip?.text = getString(R.string.app_main_left_scroll_tip)
                }
            }
        })

    }

}